<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<body></body>
<script>
description('Test case that a MutationObserver is deleted while events are collected for it. crbug.com/557981');

var div = document.createElement('div');
var div2 = document.createElement('div');
document.body.appendChild(div);

observer = new MutationObserver(function() {});
observer.observe(div, {childList: true});

var script = document.createElement('script');
script.textContent = 'unregister_observer()';
div2.appendChild(script);
div.appendChild(div2);

function unregister_observer() {
  observer.disconnect();
  delete observer;
  gc();
}
</script>
